#include<bits/stdc++.h>
using namespace std;
int t;
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin>>t;
    while(t--){
        int n, a[200003], ans = 0;
        map<int, int>mp;
        cin>>n;
        for(int i = 1;i <= n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        for(auto pa : mp){
            ans += pa.first * (pa.second - 1);
        }
        cout<<ans<<endl;
    }
}
